<?php
/**
 * VoiceOne Smarty Plugin
 *
 * Smarty function Menu
 * @package voiceone
 * @subpackage  smarty_menu
 */
 
function smarty_function_menu($params, &$smarty)
{
  global $cwUserInfo,$cwlang,$relBasePath, $cwlanguage;

  $section=$params["section"];
  $subsection=$params["subsection"];
  //Esempio: \Sites\callware3
  //$cwBasePath=substr(__FILE__,strlen(getenv("DOCUMENT_ROOT")),-strlen("\admin\public\plugin\function.menu.php"));
  //$cwBasePath=str_replace("\\","/",$cwBasePath);
	$cwBasePath=$relBasePath."..";
  
  if (strpos(getenv("REQUEST_URI"),"settings")>0) {
    if ($cwUserInfo["type"]==USER_STANDARD) {echo "<script>location.href='../';</script>"; die();}
    if ($cwUserInfo["type"]==USER_CONFIGURATOR AND (strpos(getenv("REQUEST_URI"),"lan")>0 or strpos(getenv("REQUEST_URI"),"isdn")>0)  ) {echo "<script>location.href='../';</script>"; die();} /*OR strpos(getenv("REQUEST_URI"),"user")>0)*/

    if ($section=="settings") $overview=" class=\"current\" "; else $overview="";
    if ($section=="extensions") $extensions=" class=\"current\" "; else $extensions="";
    if ($section=="voicemail") $voicemail=" class=\"current\" "; else $voicemail="";
    if ($section=="ivr") $ivr=" class=\"current\" "; else $ivr="";
    if ($section=="queue") $queue=" class=\"current\" "; else $queue="";
    if ($section=="meetme") $meetme=" class=\"current\" "; else $meetme="";
    if ($section=="providers") $provider=" class=\"current\" "; else $provider="";
    if ($section=="groups") $groups=" class=\"current\" "; else $groups="";
    if ($section=="rights") $rights=" class=\"current\" "; else $rights="";
    if ($section=="rules") $rules=" class=\"current\" "; else $rules="";
    if ($section=="offices") $offices=" class=\"current\" "; else $offices="";
    if ($section=="numbers") $numbers=" class=\"current\" "; else $numbers="";
    if ($section=="options") $options=" class=\"current\" "; else $options="";
    if ($section=="application") $application=" class=\"current\" "; else $application="";
    if ($section=="moh") $moh=" class=\"current\" "; else $moh="";
    if ($section=="sounds") $sounds=" class=\"current\" "; else $sounds="";
   
    if ($section=="isdn" or $section=="sip" or $section=="iax" or $section=="tech") $tech=" class=\"current\" "; else $tech="";
    if ($section=="lan") $lan=" class=\"current\" "; else $lan="";
    if ($section=="plugin") $plugin=" class=\"current\" "; else $plugin="";
    if ($section=="tool") $tool=" class=\"current\" "; else $tool="";
    if ($section=="system") $system=" class=\"current\" "; else $system="";
    if ($section=="voiceportal") $voiceportal=" class=\"current\" "; else $voiceportal="";
    if ($section=="user") $user=" class=\"current\" "; else $user="";
    ?>		
    <ul id="Tabs">
		   <li><a href="<?=$cwBasePath?>/settings" title="" <?=$overview?>>               <?=$cwlang["menu"]["overview"]?></a></li>
  	   <li><a href="<?=$cwBasePath?>/settings/extensions" title="" <?=$extensions?>>  <?=$cwlang["menu"]["extension"]?></a></li>
  	   <li><a href="<?=$cwBasePath?>/settings/queue" title="" <?=$queue?>>            <?=$cwlang["menu"]["queue"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/meetme" title="" <?=$meetme?>>            <?=$cwlang["menu"]["meetme"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/offices" title=""<?=$offices?>>         <?=$cwlang["menu"]["office"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/providers" title="" <?=$provider?>>     <?=$cwlang["menu"]["provider"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/numbers" title="" <?=$numbers?>>        <?=$cwlang["menu"]["number"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/groups" title="" <?=$groups?>>          <?=$cwlang["menu"]["group"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/moh" title="" <?=$moh?>>                <?=$cwlang["menu"]["moh"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/sounds" title="" <?=$sounds?>>          <?=$cwlang["menu"]["sounds"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/rules/outgoing" title="" <?=$rules?>>   <?=$cwlang["menu"][""]?>Rules</a></li>
  	   <li><a href="<?=$cwBasePath?>/settings/ivr" title="" <?=$ivr?>>                <?=$cwlang["menu"]["ivr"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/tool/application/" title="" <?=$application?>>       <?=$cwlang["menu"][""]?>Applications</a></li>

       <li><a href="<?=$cwBasePath?>/settings/system/io" title="" <?=$system?> style="float: right; margin-right: 20px;">  <?=$cwlang["menu"]["system"]?></a></li>
       <li><a href="<?=$cwBasePath?>/settings/user" title="" <?=$user?> style="float: right;">                  <?=$cwlang["menu"]["user"]?></a></li>
  <?   if ($cwUserInfo["type"]==USER_SUPERUSER) {?>   
       <li><a href="<?=$cwBasePath?>/settings/tech" title="" <?=$tech?> style="float: right;">                  <?=$cwlang["menu"]["tect"]?>Technologies</a></li>
       <li><a href="<?=$cwBasePath?>/settings/plugin" title="" <?=$plugin?> style="float: right;">                    <?=$cwlang["menu"][""]?>Plugin</a></li>
  <?   }   ?>
		</ul>
  <?
  } else {
    if ($section=="contacts") $contacts=" class=\"current\" "; else $contacts="";
    if ($section=="phone") $phone=" class=\"current\" "; else $phone="";
    if ($section=="calls") $calls=" class=\"current\" "; else $calls="";
    if ($section=="voicemail") $voicemail=" class=\"current\" "; else $voicemail="";
    if ($section=="transfers") $transfers=" class=\"current\" "; else $transfers="";
    if ($section=="settings") $settings=" class=\"current\" "; else $settings="";
    if ($section=="style") $style=" class=\"current\" "; else $templates="";
    if ($section=="account") $account=" class=\"current\" "; else $account="";
    ob_start();
    ?>		
    
      <ul id="Tabs">
  		   <li><a href="<?=$cwBasePath?>/" title="" <?=$contacts?>>           
            <?=$cwlang["menu"]["phonebook"]?></a></li>
  		   <li><a href="<?=$cwBasePath?>/phone/" title="" <?=$phone?>>           
            <?=$cwlang["menu"]["phone"]?></a></li>
    	   <li><a href="<?=$cwBasePath?>/calls" title="" <?=$calls?>  >       
            <?=$cwlang["menu"]["history"]?></a></li>      
  <? if ($cwUserInfo["entity_id"]!=0) {?>  
         <li><a href="<?=$cwBasePath?>/voicemail" title="" <?=$voicemail?>> 
            <?=$cwlang["menu"]["voicemail"]?></a></li>
  <? } ?>   	   
         <!--
         <li><a href="<?=$cwBasePath?>/transfers" title="" <?=$transfers?>> 
            <?=$cwlang["menu"]["transfer"]?></a></li>
         -->
  <? if ($cwUserInfo["type"]==USER_CONFIGURATOR OR $cwUserInfo["type"]==USER_SUPERUSER) {?>   
         <li><a href="<?=$cwBasePath?>/settings" title="" <?=$settings?> style="float: right; margin-right: 20px; color:red"> 
            <?=$cwlang["menu"]["configurator"]?></a></li>
  <? } else $margin="margin-right: 20px;"; ?>          
  <? if ($cwUserInfo["entity_id"]!=0) {?>  
         <li><a href="<?=$cwBasePath?>/account" title="" <?=$account?> style="float: right; <?=$margin?>">                                 
            <?=$cwlang["menu"]["account"]?></a></li>
  <? } ?>
  		</ul> 
  <?
    $ret=ob_get_contents();
    ob_end_clean();
  }
  return $ret;
}
?> 
